package cn.hdu.liang.generics;

import cn.hdu.liang.generics.coffee.Coffee;
import cn.hdu.liang.generics.coffee.CoffeeGenerator;
import cn.hdu.liang.generics.coffee.Generator;

import java.util.ArrayList;
import java.util.Collection;

public class Generators {
    public static <T> Collection<T> fill(Collection<T> coll, Generator<T> gen, int n) {
        for(int i = 0; i < n; i++) {
            coll.add(gen.next());
        }
        return coll;
    }

    public static void main(String[] args) {
        Collection<Coffee> coffees = fill(new ArrayList<>(), new CoffeeGenerator(), 4);
        coffees.forEach(System.out::println);

        Collection<Integer> fnumbers = fill(new ArrayList<>(), new Fibonacci(), 12);
        fnumbers.forEach(i -> System.out.print(i + " "));
    }
}
